using System;
using System.Linq;
using System.Windows.Forms;
using HomeDms.Properties;
using ImageAcquisitionTAL;
using System.Globalization;

namespace HomeDms
{
    public partial class PreferancesForm : Form
    {
        public PreferancesForm()
        {
            InitializeComponent();
        }

        private void PreferancesForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.Cancel)
                return;

            // save settings...
            Settings.Default.DefaultScanner = ((Scanner)devicesComboBox.SelectedItem).DeviceID;
            Settings.Default.DefaultMainDocumentLanguage = (comboBox1.SelectedItem as CultureInfo).Name;
            Settings.Default.Save();
        }

        private void PreferancesForm_Load(object sender, EventArgs e)
        {
            IAcquisitionTechnology tech = ImageAcquisitionTechnologyFactory.SelectSupportedTechnology();
            devicesComboBox.DataSource = tech.GetInstalledScanners();
            devicesComboBox.SelectedItem = tech.GetScanner(Settings.Default.DefaultScanner);
            var q = from cult in CultureInfo.GetCultures(CultureTypes.AllCultures)
                    orderby cult.DisplayName
                    select cult;
            comboBox1.Items.Clear();
            comboBox1.Items.AddRange(q.ToArray<CultureInfo>());
            comboBox1.SelectedItem = CultureInfo.GetCultureInfo(Settings.Default.DefaultMainDocumentLanguage);
            if (Settings.Default.DefaultMainDocumentLanguage == "")
                comboBox1.SelectedItem = CultureInfo.CurrentCulture;
        }
    }
}